package net.dopan.pigframe.user.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.dopan.pigframe.core.base.controller.BaseController;
import net.dopan.pigframe.core.base.controller.response.ResponseBean;
import net.dopan.pigframe.core.utils.CommonConstant;
import net.dopan.pigframe.core.utils.Query;
import net.dopan.pigframe.user.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Package: net.dopan.pigframe.user.controller
 * @Title: LogController
 * @Description: 日志表
 * @author: 刘宽
 * @date: 2018/9/2 21:26
 */
@RestController
@RequestMapping("/log")
@Api(tags = "日志接口(API)", description = "日志相关操作")
public class LogController extends BaseController {

    @Autowired
    private SysLogService sysLogService;

    /**
     * 分页查询日志信息
     *
     * @param params 分页对象
     * @return 分页对象
     */
    @RequestMapping("/logPage")
    @ApiOperation(value = "分页查询日志信息", notes = "分页查询日志信息")
    public Page logPage(@RequestParam Map<String, Object> params) {
        params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL);
        return sysLogService.selectPage(new Query<>(params), new EntityWrapper<>());
    }

    /**
     * 根据ID删除日志
     *
     * @param id ID
     * @return success/false
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据ID删除日志", notes = "根据ID删除日志")
    public ResponseBean<Boolean> delete(@PathVariable Long id) {
        return new ResponseBean<>(sysLogService.updateByLogId(id));
    }
}
